package basic.thread.again;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author bingo
 * @create 2018-02-09 16:40
 * 带返回值的线程
 **/
public class Demo3 implements Callable {

    public static void main(String[] args) {

        Demo3 demo3 = new Demo3();

        FutureTask<Integer> futureTask = new FutureTask(demo3);

        Thread thread = new Thread(futureTask);
        thread.start();
        System.out.println("先干点别的。。。。");
        try {
            Integer result = futureTask.get();
            System.out.println("结果:"+result);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }


    }



    @Override
    public Object call() throws Exception {
        System.out.println("正在进行紧张的计算......");
        return 1;
    }
}
